package com.test.action;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBConnect {

	private Connection con = null;
	private Statement stmt = null;
	
	private String url = "jdbc:sqlserver://localhost:1433;database=pubs";
	
	public Connection getCon(){
		
		try {
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			
			con = DriverManager.getConnection(url,"sa","sdyt");
			
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return con;
	}
	
	public static void main(String[] args) {

		DBConnect db = new DBConnect();
		
		Connection con = db.getCon();
		
		Statement stmt;
		try {
			stmt = con.createStatement();
			ResultSet rst = stmt.executeQuery("select * from jobs");
			
			while(rst.next()){
				
				System.out.println("job_id: " + rst.getString(1));
				System.out.println("job_desc: " + rst.getString(2));
			}
			
			con.close();
			stmt.close();
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
	}

}
